package main

import (
	_ "beegodemo03/routers"
	"fmt"
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/orm"
	_ "github.com/go-sql-driver/mysql"
)

func init() {

	_ = orm.RegisterDriver("mysql", orm.DRMySQL)

	// 数据库连接参数
	host := beego.AppConfig.String("db::host")
	port := beego.AppConfig.String("db::port")
	dbname := beego.AppConfig.String("db::databaseName")
	user := beego.AppConfig.String("db::userName")
	pwd := beego.AppConfig.String("db::password")

	dbcon := user + ":" + pwd + "@tcp(" + host + ":" + port + ")/" + dbname + "?charset=utf8"
	err := orm.RegisterDataBase("default", "mysql", dbcon)

	if err != nil {
		fmt.Println("注册数据源出现错误", err.Error())
	}

}

func main() {

	beego.Run()
}
